package school.baby.nem165.ui;

import school.baby.nem165.R;
import school.baby.nem165.util.Utility;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

public class StartScreenActivity extends BaseActivity {

    private boolean actif = true;

    public boolean isActif() {
        return actif;
    }

    public void setActif(boolean actif) {
        this.actif = actif;
    }

    public int getScreenTime() {
        return screenTime;
    }

    public void setScreenTime(int screenTime) {
        this.screenTime = screenTime;
    }

    protected int screenTime = 1000;
    

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.start_screen_activity);
        if (getSupportActionBar() != null) {
            getSupportActionBar().hide();
        }
    }
    @Override
	protected void onStart() {
		super.onStart();
		this.getLogerFacebook().logEvent(getClass().getSimpleName());
		continueToLogin();
		Utility.pushOpenScreenEvent(this,getClass().getSimpleName());
	}

	@Override
	protected void onStop() {
		super.onStop();
	}
	private void continueToLogin() {
		Thread screenThread = new Thread() {
            @Override
            public void run() {
                try {
                    int wait = 0;
                    while (isActif() && (wait < getScreenTime())) {
                        sleep(200);
                        if (isActif()) {
                            wait += 100;
                        }
                    }
                } catch (Exception e) {
                    Toast.makeText(getBaseContext(), "Error", Toast.LENGTH_SHORT).show();
                } finally {
                	Intent intent = new Intent(StartScreenActivity.this, HomeActivity.class);
                    startActivity(intent);
                    finish();
                }
            };

        };
        screenThread.start();
	}
}
